/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */
package utilities;

import Jama.Matrix;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments -
 */
public class CalibrateTouch {

    public double[] getMatrix(double x1, double y1, double x2, double y2, double x3, double y3, int rx1, int ry1, int rx2, int ry2, int rx3, int ry3) {
        double[][] value = {{x1, y1, 1, 0, 0, 0}, {0, 0, 0, x1, y1, 1}, {x2, y2, 1, 0, 0, 0}, {0, 0, 0, x2, y2, 1}, {x3, y3, 1, 0, 0, 0}, {0, 0, 0, x3, y3, 1}};
        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[6];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        return results;
    }

    public double[] getMatrix5(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, int rx1, int ry1, int rx2, int ry2, int rx3, int ry3, int rx4, int ry4, int rx5, int ry5) {
        double[][] value = {{x1, y1, 1, 0, 0, 0},
            {0, 0, 0, x1, y1, 1},
            {x2, y2, 1, 0, 0, 0},
            {0, 0, 0, x2, y2, 1},
            {x3, y3, 1, 0, 0, 0},
            {0, 0, 0, x3, y3, 1},
            {x4, y4, 1, 0, 0, 0},
            {0, 0, 0, x4, y4, 1},
            {x5, y5, 1, 0, 0, 0},
            {0, 0, 0, x5, y5, 1}};
        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3}, {rx4}, {ry4}, {rx5}, {ry5}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[6];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        return results;
    }

    public double[] getMatrix7(double x1, double y1, double x2, double y2, double x3, double y3,
            double x4, double y4, double x5, double y5,
            double x6, double y6, double x7, double y7,
            int rx1, int ry1, int rx2, int ry2, int rx3,
            int ry3, int rx4, int ry4, int rx5, int ry5,
            int rx6, int ry6, int rx7, int ry7) {
        double[][] value = {{x1, y1, 1, 0, 0, 0},
            {0, 0, 0, x1, y1, 1},
            {x2, y2, 1, 0, 0, 0},
            {0, 0, 0, x2, y2, 1},
            {x3, y3, 1, 0, 0, 0},
            {0, 0, 0, x3, y3, 1},
            {x4, y4, 1, 0, 0, 0},
            {0, 0, 0, x4, y4, 1},
            {x5, y5, 1, 0, 0, 0},
            {0, 0, 0, x5, y5, 1},
            {x6, y6, 1, 0, 0, 0},
            {0, 0, 0, x6, y6, 1},
            {x7, y7, 1, 0, 0, 0},
            {0, 0, 0, x7, y7, 1}};
        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3},
            {rx4}, {ry4}, {rx5}, {ry5},
            {rx6}, {ry6}, {rx7}, {ry7}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[6];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        return results;
    }

    public double[] get10Matrix7(double x1, double y1, double x2, double y2, double x3, double y3,
            double x4, double y4, double x5, double y5,
            double x6, double y6, double x7, double y7,
            int rx1, int ry1, int rx2, int ry2, int rx3, int ry3,
            int rx4, int ry4, int rx5, int ry5,
            int rx6, int ry6, int rx7, int ry7) {

        double x12 = x1 * x1;
        double x22 = x2 * x2;
        double x32 = x3 * x3;
        double x42 = x4 * x4;
        double x52 = x5 * x5;
        double x62 = x6 * x6;
        double x72 = x7 * x7;

        double y12 = y1 * y1;
        double y22 = y2 * y2;
        double y32 = y3 * y3;
        double y42 = y4 * y4;
        double y52 = y5 * y5;
        double y62 = y6 * y6;
        double y72 = y7 * y7;


        double[][] value = {
            {x12, y12, x1, y1, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x12, y12, x1, y1, 1},
            {x22, y22, x2, y2, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x22, y22, x2, y2, 1},
            {x32, y32, x3, y3, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x32, y32, x3, y3, 1},
            {x42, y42, x4, y4, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x42, y42, x4, y4, 1},
            {x52, y52, x5, y5, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x52, y52, x5, y5, 1},
            {x62, y62, x6, y6, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x62, y62, x6, y6, 1},
            {x72, y72, x7, y7, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x72, y72, x7, y7, 1}};

        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3},
            {rx4}, {ry4}, {rx5}, {ry5},
            {rx6}, {ry6}, {rx7}, {ry7}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[10];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        results[6] = C.get(6, 0);
        results[7] = C.get(7, 0);
        results[8] = C.get(8, 0);
        results[9] = C.get(9, 0);

        return results;
    }

    public double[] get10Matrix(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, int rx1, int ry1, int rx2, int ry2, int rx3, int ry3, int rx4, int ry4, int rx5, int ry5) {

        double x12 = x1 * x1;
        double x22 = x2 * x2;
        double x32 = x3 * x3;
        double x42 = x4 * x4;
        double x52 = x5 * x5;

        double y12 = y1 * y1;
        double y22 = y2 * y2;
        double y32 = y3 * y3;
        double y42 = y4 * y4;
        double y52 = y5 * y5;



        double[][] value = {{x12, y12, x1, y1, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x12, y12, x1, y1, 1},
            {x22, y22, x2, y2, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x22, y22, x2, y2, 1},
            {x32, y32, x3, y3, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x32, y32, x3, y3, 1},
            {x42, y42, x4, y4, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x42, y42, x4, y4, 1},
            {x52, y52, x5, y5, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x52, y52, x5, y5, 1},};

        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3}, {rx4}, {ry4}, {rx5}, {ry5}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[10];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        results[6] = C.get(6, 0);
        results[7] = C.get(7, 0);
        results[8] = C.get(8, 0);
        results[9] = C.get(9, 0);

        return results;
    }

    public double[] get8Matrix(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double x5, double y5, int rx1, int ry1, int rx2, int ry2, int rx3, int ry3, int rx4, int ry4, int rx5, int ry5) {

        double x12 = x1 * x1;
        double x22 = x2 * x2;
        double x32 = x3 * x3;
        double x42 = x4 * x4;
        double x52 = x5 * x5;

        double y12 = y1 * y1;
        double y22 = y2 * y2;
        double y32 = y3 * y3;
        double y42 = y4 * y4;
        double y52 = y5 * y5;



        double[][] value = {{x12, x1, y1, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y12, x1, y1, 1},
            {x22, x2, y2, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y22, x2, y2, 1},
            {x32, x3, y3, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y32, x3, y3, 1},
            {x42, x4, y4, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y42, x4, y4, 1},
            {x52, x5, y5, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y52, x5, y5, 1},};

        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3}, {rx4}, {ry4}, {rx5}, {ry5}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[8];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        results[6] = C.get(6, 0);
        results[7] = C.get(7, 0);


        return results;
    }

    public double[] get8Matrix7(double x1, double y1, double x2, double y2, double x3, double y3,
            double x4, double y4, double x5, double y5,
            double x6, double y6, double x7, double y7,
            int rx1, int ry1, int rx2, int ry2, int rx3, int ry3,
            int rx4, int ry4, int rx5, int ry5,
            int rx6, int ry6, int rx7, int ry7) {

        double x12 = x1 * x1;
        double x22 = x2 * x2;
        double x32 = x3 * x3;
        double x42 = x4 * x4;
        double x52 = x5 * x5;
        double x62 = x6 * x6;
        double x72 = x7 * x7;

        double y12 = y1 * y1;
        double y22 = y2 * y2;
        double y32 = y3 * y3;
        double y42 = y4 * y4;
        double y52 = y5 * y5;
        double y62 = y6 * y6;
        double y72 = y7 * y7;


        double[][] value = {
            {x12, x1, y1, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y12, x1, y1, 1},
            {x22, x2, y2, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y22, x2, y2, 1},
            {x32, x3, y3, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y32, x3, y3, 1},
            {x42, x4, y4, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y42, x4, y4, 1},
            {x52, x5, y5, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y52, x5, y5, 1},
            {x62, x6, y6, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y62, x6, y6, 1},
            {x72, x7, y7, 1, 0, 0, 0, 0},
            {0, 0, 0, 0, y72, x7, y7, 1}};

        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2},
            {rx3}, {ry3}, {rx4}, {ry4}, {rx5}, {ry5}, {rx6}, {ry6}, {rx7}, {ry7}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[8];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        results[6] = C.get(6, 0);
        results[7] = C.get(7, 0);


        return results;
    }

    public double[] get10Matrix8(double x1, double y1, double x2, double y2, double x3, double y3,
            double x4, double y4, double x5, double y5,
            double x6, double y6, double x7, double y7, double x8, double y8,
            int rx1, int ry1, int rx2, int ry2, int rx3, int ry3,
            int rx4, int ry4, int rx5, int ry5,
            int rx6, int ry6, int rx7, int ry7, int rx8, int ry8) {

        double x12 = x1 * x1;
        double x22 = x2 * x2;
        double x32 = x3 * x3;
        double x42 = x4 * x4;
        double x52 = x5 * x5;
        double x62 = x6 * x6;
        double x72 = x7 * x7;
        double x82 = x8 * x8;

        double y12 = y1 * y1;
        double y22 = y2 * y2;
        double y32 = y3 * y3;
        double y42 = y4 * y4;
        double y52 = y5 * y5;
        double y62 = y6 * y6;
        double y72 = y7 * y7;
        double y82 = y8 * y8;


        double[][] value = {
            {x12, y12, x1, y1, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x12, y12, x1, y1, 1},
            {x22, y22, x2, y2, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x22, y22, x2, y2, 1},
            {x32, y32, x3, y3, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x32, y32, x3, y3, 1},
            {x42, y42, x4, y4, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x42, y42, x4, y4, 1},
            {x52, y52, x5, y5, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x52, y52, x5, y5, 1},
            {x62, y62, x6, y6, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x62, y62, x6, y6, 1},
            {x72, y72, x7, y7, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x72, y72, x7, y7, 1},
            {x82, y82, x8, y8, 1, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, x82, y82, x8, y8, 1}};

        Matrix fr = new Matrix(value);
        double[][] res = {{rx1}, {ry1}, {rx2}, {ry2}, {rx3}, {ry3},
            {rx4}, {ry4}, {rx5}, {ry5},
            {rx6}, {ry6}, {rx7}, {ry7}, {rx8}, {ry8}};
        Matrix B = new Matrix(res);
        Matrix C = fr.solve(B);
        double[] results = new double[10];
        results[0] = C.get(0, 0);
        results[1] = C.get(1, 0);
        results[2] = C.get(2, 0);
        results[3] = C.get(3, 0);
        results[4] = C.get(4, 0);
        results[5] = C.get(5, 0);
        results[6] = C.get(6, 0);
        results[7] = C.get(7, 0);
        results[8] = C.get(8, 0);
        results[9] = C.get(9, 0);

        return results;
    }
}
